{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- [FOURCC四字符码对照表](https://blog.csdn.net/qq_30622831/article/details/82082122)\n",
    "- [【视频编码格式】全面解析](https://blog.csdn.net/baidu_39511645/article/details/78442819)\n",
    "\n",
    "- [高清视频编码 哪种格式的视频更清晰](http://www.360doc.com/content/15/0215/23/14534301_448873274.shtml)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# coding:utf8\n",
    "import cv2\n",
    "\"\"\"\n",
    "读取视频文件的帧， 采用yuv颜色编码写入到另一个帧\n",
    "\n",
    "VideoCapture和VideoWriter用于视频文件的读写\n",
    "VideoCapture读的每一帧都是一个bgr格式的图像\n",
    "\"\"\"\n",
    "videoCapture = cv2.VideoCapture(\"../data/demo3.mp4\")\n",
    "fps = videoCapture.get(cv2.CAP_PROP_FPS)\n",
    "size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),\n",
    "        int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))\n",
    "\n",
    "videoWriter = cv2.VideoWriter(\n",
    "    \"output.mp4\",\n",
    "    cv2.VideoWriter_fourcc(\"I\", \"4\", \"2\", \"0\"),  # 编码器\n",
    "    fps,\n",
    "    size)\n",
    "'''\n",
    "编码器常用的几种：\n",
    "cv2.VideoWriter_fourcc(\"I\", \"4\", \"2\", \"0\") \n",
    "    压缩的yuv颜色编码器，4:2:0色彩度子采样 兼容性好，产生很大的视频 avi\n",
    "cv2.VideoWriter_fourcc(\"P\", I\", \"M\", \"1\")\n",
    "    采用mpeg-1编码，文件为avi\n",
    "cv2.VideoWriter_fourcc(\"X\", \"V\", \"T\", \"D\")\n",
    "    采用mpeg-4编码，得到视频大小平均 拓展名avi\n",
    "cv2.VideoWriter_fourcc(\"T\", \"H\", \"E\", \"O\")\n",
    "    Ogg Vorbis， 拓展名为ogv\n",
    "cv2.VideoWriter_fourcc(\"F\", \"L\", \"V\", \"1\")\n",
    "    FLASH视频，拓展名为.flv\n",
    "'''\n",
    "\n",
    "success, frame = videoCapture.read()\n",
    "while success:  # 循环直到没有帧了\n",
    "    videoWriter.write(frame)\n",
    "    success, frame = videoCapture.read()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
